#include "SplashState.h"
#include "MenuState.h"

#include "..\Game.h"

#include "..\Definitions.h"
#include "..\..\SGD Wrappers\SGD_GraphicsManager.h"
#include "..\..\SGD Wrappers\SGD_InputManager.h"

/**************************************************************/
// GetInstance
//	- store the ONLY instance in global memory
//	- return the only instance by pointer
/*static*/ SplashState* SplashState::GetInstance(void)
{
	static SplashState s_Instance;

	return &s_Instance;
}

void SplashState::Enter()
{
	fTimer = 0.0f;
	fRotateFantasyFallLogo = 0.0f;
	fDropFantasyFallLogo = 0.0f;
	teamLogoScale.width = 0.05f;
	teamLogoScale.height = 0.05f;
}

void SplashState::Exit()
{
}

bool SplashState::Update(float dt)
{
	fTimer += dt;

	pTeamLoc.x = 50 + fTimer * 30;
	pTeamLoc.y = 50 + fTimer * 30;

	// Increment Team Logo Scale by fTimer
	teamLogoScale.width = fTimer;
	teamLogoScale.height = fTimer;
	// Cap Team Logo Scale to 1.0f
	if (teamLogoScale.width >= 1.0f)
	{
		teamLogoScale.width = 1.0f;
		teamLogoScale.height = 1.0f;
	}

	if(fTimer >= 2.5f)
		// Rotate Fantasy Fall Logo and Drop by fTimer
		fRotateFantasyFallLogo = fTimer - 2.5f;

	if (fTimer >= 3.75f)
		//fRotateFantasyFallLogo = 1.75f;
		fDropFantasyFallLogo += 500 * dt;

	if (SGD::InputManager::GetInstance()->IsAnyKeyPressed() || fTimer > 5)
		GAME->ChangeState(MenuState::GetInstance());

	return true;
}

void SplashState::Render()
{

	SGD::Point pCenter{ GAME->GetScreenWidth(), GAME->GetScreenHeight() };
	if (fTimer < 2)
	{
		GRAPHICS->DrawTexture(GAME->hTeamLogoImage, pTeamLoc, 0.0f, {}, {}, teamLogoScale);
	}
	if (fTimer > 2)
	{
		SGD::Point pGameLogoLoc{ pCenter.x / 2 - 250, pCenter.y / 2 - 100 + fDropFantasyFallLogo };
		GRAPHICS->DrawTexture(GAME->hFantasyFallLogoImage, pGameLogoLoc, fRotateFantasyFallLogo);
	}
}